//
//  ZDBRankListInfoView.m
//  ZDB
//
//  Created by 微笑吧阳光 on 2020/3/16.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBRankListInfoView.h"

@implementation ZDBRankListInfoView


-(void)awakeFromNib{
    [super awakeFromNib];
    
    self.tishiLab.hidden = YES;
    KViewRadius(self.bgView, 5);
    KViewRadius(self.headerImage, 20);
    self.bgImage.hidden = YES;
    
    //self.bgImage.image = [UIImage imageNamed:@"Rank_mybg"];
}


-(void)refushData:(NSArray *)dataArry{

    
}

-(void)refushUserInfoModel:(ZDBRankListModel*)modell andArry:(NSArray *)arry{
    
    self.nameLab.text = modell.nikeName;
    self.jineLab.text = [NSString stringWithFormat:@"¥%ld",(long)[modell.money integerValue]];
    [self.headerImage sd_setImageWithURL:[NSURL URLWithString:modell.headImage] placeholderImage:PlaceHolderImage];
    
    NSMutableArray * dataArry = [NSMutableArray array];
    
    for (ZDBRankListModel * listModel  in arry) {
        if ([listModel.nikeName isEqualToString:modell.nikeName]) {
            [dataArry addObject:listModel];
        }
    }
    
    if (dataArry.count >0) {
        //自己上榜了
        ZDBRankListModel * listModel = dataArry.firstObject;
        NSInteger indexx = [arry indexOfObject:listModel];
        self.numLab.text = [NSString stringWithFormat:@"%d",indexx+1];
        
        if (indexx ==0) {
            self.tishiLab.text = @"恭喜您，位居榜首";
        }else{
            ZDBRankListModel * listModel = [arry objectAtIndex:indexx-1];
            NSInteger num = [listModel.money integerValue]-[modell.money integerValue];
            self.tishiLab.text = [NSString stringWithFormat:@"距离上一名还差¥%ld",(long)num];
        }
    }else{
       //自己没上榜
        self.numLab.text = @"未上榜";
        
        if (arry.count>0) {
            ZDBRankListModel * listModel = arry.lastObject;
            NSInteger num = [listModel.money integerValue]-[modell.money integerValue];
            self.tishiLab.text = [NSString stringWithFormat:@"距离第%lu名还差¥%ld",arry.count+3,(long)num];
            
        }else{
            
            self.tishiLab.text = @"";
        }
        
    }
   
}
@end
